<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="format-detection" content="telephone=no" />
    <meta name="format-detection" content="email=no" />
    <title>我的</title>
    <link rel="stylesheet" href="../../css/api.css">
    <link rel="stylesheet" href="../../css/vant.css">
    <link rel="stylesheet" href="../../css/main.css">
    <style>
        .disable {
            pointer-events: none
        }

        .app {
            /* height: 100%; */
            /* overflow-y: auto; */
        }

        .wd-list {
            overflow-y: auto;
        }

        .wd-head .wd-right-horn .info {
            position: relative;
        }

        .wd-head .wd-right-horn .info.redDot::after {
            content: ' ';
            background: #F53B31;
            position: absolute;
            top: -.035rem;
            right: -.035rem;
            border-radius: 50%;
            width: .07rem;
            height: .07rem;
            z-index: 9999;
        }

        .wd-list-item-v2 {
            padding: .1rem .12rem;
            border-bottom: 0.01rem solid #f5f5f5;
        }

        .wd-list-item-v2-f2 {
            margin-top: .1rem;
            font-size: .12rem;
            color: #666;
        }

        .fill-footer {
            height: 1.5rem;
        }
    </style>
</head>

<body>
    <div class="app" v-cloak>
        <div class="wd-head">
            <div class="wd-nickname" @click="goPage('login_center')">
                <img :src="baseInfo.headUrl?baseInfo.headUrl:'https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/mine/head_portrait.png'" alt="">
                <div v-if="isLogin">{{baseInfo.nickName ? baseInfo.nickName : '昵称'}}</div>
                <div v-else>登录</div>
            </div>
            <div class="wd-right-horn">
                <span class="info" :class="{redDot: unReadNum > 0}">
                    <img style="object-fit: fill;" src="https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/info.png" alt="" @click="goPage('info')">
                </span>
                <span>
                    <img src="https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/mine/scan.png" alt="" @click="scan">
                </span>
            </div>
            <div class="wd-icon flex-x-sb flex-wrap">
                <!-- 六个icon .wd-icon-itemV2 6个icon  :class="{'wd-icon-itemV2':systemSet.onlineBuyEnabled}"-->
                <div class="wd-icon-item wd-icon-itemV2" v-for="(item,index) in iconList" :key="index"
                    @click="goPage(item.url, '', item.name)">
                    <img :src="item.path" alt="">
                    <div>{{item.name}}</div>
                </div>
            </div>
        </div>
        <!--底部菜单 <div class="wd-list" :class="{'wd-listV2':systemSet.onlineBuyEnabled}"> -->
        <div class="wd-list wd-listV2">
            <!--如果个人认证通过或者商家认证通过则不显示-->
            <div class="wd-list-item flex-x-sb" @click="goPage('cart',1)">
                <div>我的购物车</div>
                <div>
                    {{cartCount}}
                    <span class="iconfont">&#xe666;</span>
                </div>
            </div>
            <div class="wd-list-item flex-x-sb" @click="goPage('mine_discounts',1)" v-show="false">
                <div>我的优惠码</div>
                <div>
                    <!-- {{getStatusLabel(authStatus.personal)}} -->
                    <span class="iconfont">&#xe666;</span>
                </div>
            </div>
      
            <div class="wd-list-item flex-x-sb" v-show="isShowWallet" @click="goPage('mine_wallet',1)">
                <div>我的钱包</div>
                <div>
                    <span class="iconfont">&#xe666;</span>
                </div>
            </div>
                  <div class="wd-list-item flex-x-sb" v-show="isShowInvite" @click="goPage('invite_friend',1)">
                <div>邀请好友</div>
                <div>
                    <span class="iconfont">&#xe666;</span>
                </div>
            </div>
            <div class="wd-list-item flex-x-sb" v-if="authPersonalShow()" @click="goPage('personal_certification',1)">
                <div>个人认证</div>
                <div>
                    {{getStatusLabel(authStatus.personal)}}
                    <span class="iconfont">&#xe666;</span>
                </div>
            </div>
            <div class="wd-list-item flex-x-sb" v-if="authStatus.personal === 1  && authStatus.merchant !== 1"
                @click="(authStatus.personal === 1) && goPage('store')">
                <div>个人认证</div>
                <div>
                    {{getStatusLabel(authStatus.personal)}}
                    <span class="iconfont">&#xe666;</span>
                </div>
            </div>
            <div class="wd-list-item flex-x-sb" v-if="authStatus.merchant == 1"
                @click="(authStatus.merchant === 1) && goPage('store')">
                <div>我的店铺</div>
                <div>
                    {{getStatusLabel(authStatus.merchant)}}
                    <span class="iconfont">&#xe666;</span>
                </div>
            </div>
            <div class="wd-list-item flex-x-sb" v-if="authStatus.merchant !== 1"
                @click="goPage('store_certification',1)">
                <div>企业认证</div>
                <div>
                    {{getStatusLabel(authStatus.merchant)}}
                    <span class="iconfont">&#xe666;</span>
                </div>
            </div>
            <!-- <div class="wd-list-item flex-x-sb" @click="goPage('questionnaire',1)">
                <div>调查问卷</div>
                <span class="iconfont">&#xe666;</span>
            </div> -->
            <div class="wd-list-item flex-x-sb" @click="goFeedBackPage">
                <div>意见反馈</div>
                <span class="iconfont">&#xe666;</span>
            </div>
            <div class="wd-list-item flex-x-sb" @click="goPage('common', 1, '常见问题', '4')">
                <div>常见问题</div>
                <span class="iconfont">&#xe666;</span>
            </div>
            <div class="wd-list-item-v2">
                <div class="wd-list-item-v2-f1 flex-x-sb">
                    <div>个性化推荐</div>
                    <van-switch v-model="checked" @change="onSwitch" />
                </div>
                <div class="wd-list-item-v2-f2">我们可能会根据您的个人信息向您展示您可能感兴趣的内容；关闭后将不能为您提供个性化推荐服务；</div>
            </div>
            <div class="wd-list-item flex-x-sb" @click="goPage('common', 1, '关于我们', '1')">
                <div>关于我们</div>
                <span class="iconfont">&#xe666;</span>
            </div>
            <div class="wd-list-item flex-x-sb" @click="goPersionPrivacy">
                <div>个人协议</div>
                <span class="iconfont">&#xe666;</span>
            </div>
            <div class="wd-list-item flex-x-sb" @click="goPrivacy">
                <div>隐私协议</div>
                <span class="iconfont">&#xe666;</span>
            </div>
        </div>
        <div class="wd-signOut" v-if="isLogin">
            <span @click="logout">退出登录</span>
        </div>
        <div class="fill-footer">

        </div>
    </div>
    <script src="../../script/api.js"></script>
    <script src="../../script/flexible.js"></script>
    <script src="../../script/fastclick.js"></script>
    <script src="../../script/vue.min.js"></script>
    <script src="../../script/iconfont.js"></script>
    <script src="../../script/vant.min.js"></script>
    <script src="../../script/restful.js"></script>
    <script src="../../script/common.js"></script>
    <script src="../../script/businessCommon.js"></script>
    <script>
        apiready = function () {
            vm = new Vue({
                el: '.app',
                data: {
                    cartCount: 0,//购物车数量
                    checked: false,
                    iconList: [],
                    isLogin: false,
                    // 个人认证 商家认证
                    authStatus: {
                        merchant: '',
                        personal: ''
                    },
                    baseInfo: {
                        headUrl: '',
                        nickName: ''
                    },
                    systemSet: {},
                    auth: {
                        scanToken: null
                    },
                    unReadNum: 0,
                    isShowWallet:false,//是否显示钱包
                    isShowInvite:false
                },
                mounted: function () {
                    this.checked = $api.getStorage('recomSwitch') == 1 ? true : false;
                    this.systemSet = $api.getStorage('systemSet');
                    this.initIconInfo(this.systemSet)
                    var token = $api.getStorage('accessToken')
                    if (token) {
                        this.getBaseInfo()
                        this.getAuthorizationStatus()
                        this.getUnReadNum()
                        this.initCarts()
                    } else {
                        this.isLogin = false
                    }
                    this.getSystemSet()
                },
                methods: {
                    getSystemSet() {
                        var vm = this;
                        common('getSystemSet')({}, function (ret) {
                            //是否显示钱包入口
                            if(api.appVersion != ret.data.appModifyVersion&&ret.data.onlineWalletEnabled){
                                vm.isShowWallet = true
                            }else{
                                vm.isShowWallet = false
                            }
                            //是否显示邀请入口
                            console.log("当前版本号"+api.appVersion +"返回版本号"+ ret.data.appModifyVersion )
                            if(api.appVersion != ret.data.appModifyVersion&&ret.data.onlineBonusEnabled){
                                vm.isShowInvite = true
                            }else{
                                vm.isShowInvite = false
                            }
                        })
                    },

                    initCarts() {
                        var vm = this;
                        cart("getCartList")({}, function (ret) {
                            if (ret.data.length > 0) {
                                vm.cartCount = ret.data.length
                            }
                        })
                    },

                    onSwitch(value) {
                        console.log(value);
                        var recomSwitch = value ? 1 : 0
                        $api.setStorage('recomSwitch', recomSwitch);
                    },
                    goPrivacy: function (e) {
                        api.openWin({
                            name: 'common',
                            url: '../mine/common_win.html',
                            bounces: false,
                            pageParam: {
                                title: '隐私协议',
                                contentType: '2'
                            }
                        });
                    },
                    goPersionPrivacy: function (e) {
                        api.openWin({
                            name: 'common',
                            url: '../mine/common_win.html',
                            bounces: false,
                            pageParam: {
                                title: '个人协议',
                                contentType: '5'
                            }
                        });
                    },
                    initIconInfo(systemSet) {
                        //  if (systemSet.onlineBuyEnabled) {
                        this.iconList = [{
                            path: 'https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/mine/order.png',
                            name: '我的订单',
                            url: 'my_order'
                        }, {
                            path: 'https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/mine/address.png',
                            name: '我的地址',
                            url: 'mine_addr'
                        }, {
                            path: 'https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/mine/release.png',
                            name: '我的发布',
                            url: 'my_release'
                        }, {
                            path: 'https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/mine/collect.png',
                            name: '我的收藏',
                            url: 'collectandvisited'
                        }, {
                            path: 'https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/mine/history.png',
                            name: '浏览历史',
                            url: 'collectandvisited'
                        }, {
                            path: 'https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/mine/moment.png',
                            name: '我的动态',
                            url: 'mine_dynamic'
                        }]
                        //  }
                        //  else {
                        //     this.iconList = [{
                        //         path: 'https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/mine/collect.png',
                        //         name: '我的收藏',
                        //         url: 'collectandvisited'
                        //     }, {
                        //         path: 'https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/mine/history.png',
                        //         name: '浏览历史',
                        //         url: 'collectandvisited'
                        //     }, {
                        //         path: 'https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/mine/release.png',
                        //         name: '我的发布',
                        //         url: 'my_release'
                        //     }, {
                        //         path: 'https://zzzzkj.oss-cn-shanghai.aliyuncs.com/static/tiexie/app/image/image/mine/moment.png',
                        //         name: '我的动态',
                        //         url: 'mine_dynamic'
                        //     }]
                        // }
                    },
                    getStatusLabel(status) {
                        if (status === -1) {
                            return "未认证"
                        } else if (status === 0) {
                            return "审核中"
                        } else if (status === 1) {
                            return "已认证"
                        } else if (status === 2) {
                            return "审核拒绝"
                        } else {
                            return ''
                        }
                    },

                    goFeedBackPage: function () {
                        api.openWin({
                            name: 'send_feedback_win',
                            url: 'send_feedback_win.html',
                            bounces: false,
                            pageParam: {
                                title: '意见反馈'
                            }
                        });
                    },
                    authPersonalShow: function () {
                        if (this.authStatus.merchant === 1) {
                            return false
                        }
                        if (this.authStatus.personal !== 1) {
                            return true
                        } else {
                            return false
                        }
                    },

                    goPage(urlName, type, title, contentType) {
                        console.log(urlName)
                        if (urlName != 'common') {
                            if (!checkToken()) return false;
                        }
                        // if (urlName == 'personal_certification') {
                        //     if (this.authStatus.personal == 0){
                        //         toastMiddle('认证审核中！')
                        //         return
                        //     }
                        // }
                        // if (urlName == 'store_certification') {
                        //     if(this.authStatus.merchant == 0){
                        //         toastMiddle('认证审核中！')
                        //         return
                        //     }
                        // }
                        var url = '',
                            name = ''
                        if (urlName == 'my_release' && this.authStatus.merchant != 1 && this.authStatus.personal != 1) {
                            toastMiddle('认证通过后方可查看')
                            return
                        }
                        if (urlName == 'mine_dynamic') {
                            type = 1
                        }
                        if (urlName == 'login_center') {
                            type = this.isLogin ? 1 : 0
                            urlName = this.isLogin ? 'mine_center' : 'login'
                        }
                        if (type == 1) {
                            name = `${urlName}_win`
                            url = `${urlName}_win.html`
                        } else {
                            name = `${urlName}_win`
                            url = `../${urlName}/${urlName}_win.html`
                        }
                        if (urlName === "mine_addr") {
                            name = "addr_win"
                            url = "../address/address_list_win.html"
                        } else if (urlName === "info") {
                            name = "info_win"
                            url = "../info/info_win.html"
                        }

                        if (urlName == "cart") {
                            name = "cart_win"
                            url = "../store/cart_win.html"
                        }
                        api.openWin({
                            name: name,
                            url: url,
                            bounces: false,
                            pageParam: {
                                title: title,
                                contentType: contentType
                            }
                        });
                    },
                    logout() {
                        var vm = this;
                        api.confirm({
                            title: '退出登录',
                            buttons: ['确定', '取消']
                        }, function (ret, err) {
                            if (ret.buttonIndex == 1) {
                                common("logout")(function (ret) {
                                    vm.unReadNum = 0
                                    vm.isLogin = false
                                    vm.baseInfo = {}
                                    vm.authStatus = {
                                        merchant: -1,
                                        personal: -1
                                    }
                                    $api.rmStorage('accessToken');
                                })
                            }
                        });
                    },
                    getUnReadNum() {
                        var token = $api.getStorage('accessToken')
                        if (token) {
                            let vm = this
                            common('getUnReadNum')(function (ret) {
                                vm.unReadNum = ret.data
                            })
                        }
                    },
                    getAuthorizationStatus() {
                        let vm = this
                        mime("getAuthorizationStatus")(function (ret) {
                            console.log("@@:" + JSON.stringify(ret))
                            vm.authStatus.merchant = ret.data.merchant
                            vm.authStatus.personal = ret.data.personal
                        })
                    },
                    getBaseInfo: function () {
                        const vm = this
                        fnGet(interfaces.USER_MODULE.GET_USER_BASE_INFO, {}, true, (ret) => {
                            if (ret && ret.code === RESPONSE_OK) {
                                console.log(JSON.stringify(ret))
                                vm.$set(vm.baseInfo, 'headUrl', ret.data.headUrl)
                                vm.$set(vm.baseInfo, 'nickName', ret.data.nickName)
                                vm.isLogin = true
                            }
                        })
                    },
                    scan: function () {
                        var resultList = api.hasPermission({
                            list: ['camera']
                        });
                        var vm = this;
                        if (resultList[0].granted) {
                            vm.doCamera()
                        } else {
                            api.confirm({
                                msg: '应用需要您的授权才能访问相机',
                                buttons: ['取消', '去设置']
                            }, function (ret) {
                                if (ret.buttonIndex == 2) {
                                    api.requestPermission({
                                        list: ['camera'],
                                    }, function (res) {
                                        if (res.list[0].granted) {
                                            vm.doCamera()
                                        }
                                    });
                                }
                            });
                        }
                    },
                    doCamera() {
                        let vm = this
                        var FNScanner = api.require('FNScanner');
                        const param = {
                            autorotation: true,
                            isAlbum: true,
                            isLight: true,
                            hintText: '对准二维码，即可自动扫描'
                        }
                        FNScanner.openScanner(param, function (ret, err) {
                            if (ret && ret.eventType === 'success') {
                                vm.auth.scanToken = ret.content
                                mime("scanQrCode")(ret.content, function (ret) {
                                    api.confirm({
                                        title: '是否确认登录？',
                                        buttons: ['取消', '确认']
                                    }, function (retb, err) {
                                        if (retb.buttonIndex == 2) {
                                            vm.scanConfirm()
                                        }
                                    });
                                })
                            } else {
                                console.log(JSON.stringify(err));
                            }
                        });
                    },
                    // 扫描确认登陆
                    scanConfirm: function () {
                        let vm = this
                        mime("scanConfirmLogin")(vm.auth.scanToken, function (ret) {
                            toastMiddle('登录成功~')
                        })
                    }
                },
            })

            api.addEventListener({ name: 'updateUserInfo' }, () => {
                setTimeout(() => vm.getBaseInfo(), 300)
            });
            api.addEventListener({
                name: 'login'
            }, function (ret, err) {
                vm.getBaseInfo()
                vm.getAuthorizationStatus()
                vm.getUnReadNum()
            })
            api.addEventListener({
                name: 'updateShopStatus'
            }, function (ret, err) {
                vm.getAuthorizationStatus();
            });
            api.addEventListener({
                name: 'refreshUnReadMessageNum'
            }, function (ret, err) {
                if (!ret.value.page) {
                    vm.getUnReadNum()
                }
            });
        }
    </script>
</body>

</html>